<template>
    <div class="goods_all">
        <div class="itemlist" v-for="(item, index) in goodslist" :key="item.id" @click="goToinfo(item.id)">
            <div class="div_img">
                <img :src="item.img_url" alt="">
            </div>
            
            <p class="g_title">{{item.title}}</p>
            <div class="list_bottom">
                <p class="bottom_money">
                    <span>￥{{item.sell_price}}</span>
                    <span>￥{{item.market_price}}</span>
                </p>
                <p class="bottom_shengyu">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </div>
        <mt-button plain  size="large" type="danger" @click="jiazai">加载更多</mt-button>
    </div>
    
</template>

<script>
    import {Toast} from 'mint-ui'
    export default {
        data () {
            return {
                pageindex:1,
                goodslist:[]
            }
        },
        created() {
            this.getgoodslist();
        },
        methods: {
            getgoodslist(){
                this.$http.get('api/getgoods?pageindex='+this.pageindex).then(res=>{
                    if(res.body.status==0){
                        this.goodslist = this.goodslist.concat(res.body.message);
                    }else{
                        Toast("请求失败");
                    }
                });
            },
            jiazai(){
                this.pageindex++;
                this.getgoodslist();
            },
            goToinfo(id){
                this.$router.push({name:"goodsinfo",params:{id:id}});
            }
        }
    }
</script>

<style lang="scss" scoped>
.goods_all{
    display: flex;
    flex-wrap: wrap;
    padding: 6px;
    width: 100%;
    justify-content: space-between;
    .itemlist{
        box-shadow: 0 0 1px 1px #ddd;
        border: 1px solid #ccc;
        width: 49%;
        padding: 3px 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin: 3px 0;
        .div_img{
            width: 100%;
            text-align: center;
            img{
                margin: 0 auto; 
                width: 150px;
                height: 150px;
                margin-top: 5px;
            }
        }
        .g_title{
            color: #000;
            font-size: 14px;
            font-weight: 600;
            margin-bottom: 0px;
            line-height: 18px;
        }
        .list_bottom{
            background-color: #ddd;
            .bottom_money{
                margin: 0;
                padding: 10px;
                span:nth-child(1){
                    font-size: 18px;
                    color: red;
                    margin-right: 10px;
                }
                span:nth-child(2){
                    color: #808080;
                    text-decoration:line-through; 
                }
            }
            .bottom_shengyu{
                margin: 0;
                padding: 0 10px 10px;
                display: flex;
                justify-content: space-between;
                span{
                    color: #808080;
                }
            }
        }
    }
}
</style>